#ifndef MAIN_SCAN_H
#define MAIN_SCAN_H

#include <QWidget>
#include"parameter_set.h"
#include"scan_thread.h"
#include <bits/stdc++.h>
#include <QDebug>
#include<QThread>
#include <QObject>
#include<QThread>
#include<QMutex>
#include<bits/stdc++.h>
#include<QTcpSocket>
#include<QUdpSocket>
QT_BEGIN_NAMESPACE
namespace Ui {
class main_scan;
}
QT_END_NAMESPACE

class main_scan : public QWidget
{
    Q_OBJECT

public:
    main_scan(QWidget *parent = nullptr);
    ~main_scan();
    static QMutex *mtx;
private slots:
    void on_parameter_set_pbn_clicked();
    void get_parameter_end_set_result(QStringList ip_list,std::pair<int,int>conseq_ports,std::vector<int>ports,int thread_cnt);
    void get_started_inform();
    void get_pause_inform();
    void get_stop_inform();
    void on_scan_start_pbn_clicked();
    void on_parameter_reset_pbn_clicked();
    void on_scan_condition_clear_pbn_clicked();
    void get_draw_scan_condition_inform(QString x);
    void on_scan_pause_pbn_clicked();
    void on_scan_break_pbn_clicked();

    void on_query_clear_pbn_clicked();

    void on_query_pbn_clicked();

    void on_scan_condition_flush_pbn_clicked();

    void on_scan_save_pbn_clicked();

    void on_scan_exit_pbn_clicked();

    void m_exited();

    void exit_display();

    void g_exit();
signals:
    void draw_scan_condition(QString);
    void has_all_exited();
    void exit_tip();
    void p_exit();
private:
    Ui::main_scan *ui;
    parameter_set *p_set;
    int started_cnt;
    int paused_cnt;
    int stopped_cnt;//用于统计多线程下暂停的线程数和停止的线程数
    std::queue<scan_thread*>*q;
    std::vector<scan_thread*>*bank;//bank of scan thread
    int task_cnt;//count of task;
    int base_t;
    int res_cnt;
    int total_task_cnt;//from the set
    int thd_cnt;//from the set
    bool exited;
    void cl_scan_condition_field();
    //记录所有要输出的扫描情况，等待要输出的扫描情况大于两倍的线程再输出
    std::queue<QString>scan_condition_queue;
    QString scan_condition_body;
    //用于记录最后一次扫描信息的部分
    std::vector<std::pair<std::pair<QString,int>,std::pair<QString,bool>>>*open_,*close_;
    std::map<std::pair<QString,int>,QString>*query_bank;
};
#endif // MAIN_SCAN_H
